// components/PayBar/PayBar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    total: {
      type: Number,
      default: 0
    },
    goodsCount: {
      type: Number,
      default: 0
    },
    isAllCheck: {
      type: Boolean,
      default: false
    },
    showAllCheck: {
      type: Boolean,
      value: true
    },
    message: {
      type: String,
      value: '结算'
    },
    isPay: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    checked: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    gotoPay(){
      console.log(this.data.isPay)
      if(this.data.isPay){
        wx.requestPayment({
          nonceStr: 'nonceStr',
          package: 'package',
          paySign: 'paySign',
          timeStamp: 'timeStamp',
        })
      } else {
        wx.redirectTo({
          url: `/pages/pay/pay?total=${this.data.goodsCount}&price=${this.data.total}`,
        })
      }
    },
    checkBtn(){
      this.setData({
        checked: this.data.checked? false : true
      });
      this.triggerEvent('checkAll', this.data.checked);
    }

  },
  observers:{
    'isAllCheck': function(isAllCheck){
      // console.log(isAllCheck)
      isAllCheck? this.setData({checked: true}) : this.setData({checked: false});
    }
  }
})
